package class_test.test1_0330;

import java.util.Scanner;

/**
 * @author haomin
 * @date 2022/03/30 16:47
 **/
public class QuadraticEquationTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入a，b，c的值：");
        double a = scanner.nextInt();
        double b = scanner.nextInt();
        double c = scanner.nextInt();

        //new 一个对象（使用有参构造）
        QuadraticEquation qe = new QuadraticEquation(a,b,c);

        if(qe.getDiscriminant() < 0){
            System.out.println("The equation has no roots.");
        }else if(qe.getDiscriminant() == 1){
            System.out.println("r:" + qe.getRoot1());
        }else {
            System.out.println("r:" + qe.getRoot1());
            System.out.println("r:" + qe.getRoot2());
        }
    }
}

class QuadraticEquation{
    private double a,b,c;

    public QuadraticEquation(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double getDiscriminant(){
        return b * b - 4 * a * c;
    }
    public double getRoot1(){
        return ((-b) + Math.sqrt(b*b-4*a*c)) / (2*a);
    }
    public double getRoot2(){
        return ((-b) - Math.sqrt(b*b-4*a*c)) / (2*a);
    }
}